package com.zhongxi.guoyuan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhongxi.guoyuan.R;

/**
 * Created by Administrator on 2016/11/20.
 */

public class PersonCenterAdapter extends BaseAdapter {

    private LayoutInflater mLayoutInflater;
    private String[] names;
    private int[] imgs;

    public PersonCenterAdapter(Context context, int[] imgs, String[] names) {
        mLayoutInflater = LayoutInflater.from(context);
        this.imgs = imgs;
        this.names = names;
    }

    @Override
    public int getCount() {
        return names.length;
    }

    @Override
    public Object getItem(int position) {
        return names[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = mLayoutInflater.inflate(R.layout.item_person_gv, parent, false);
            holder.ivImg = (ImageView) convertView.findViewById(R.id.ivImg);
            holder.tvName = (TextView) convertView.findViewById(R.id.tvName);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.ivImg.setImageResource(imgs[position]);
        holder.tvName.setText(names[position]);
        return convertView;
    }

    class ViewHolder{
        private ImageView ivImg;
        private TextView tvName;
    }
}
